package org.eae.eldf.dao.base.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.eae.eldf.dao.base.IBaseLanguageDao;
import org.eae.eldf.dto.base.BaseLanguageDto;
import org.eae.eldf.framework.dao.JdbcDaoImpl;
import org.eae.eldf.framework.pager.Pagination;
import org.springframework.stereotype.Repository;
@Repository
public class IBaseLanguageDaoImpl extends JdbcDaoImpl implements IBaseLanguageDao{
	
	/**
	 *分页查询关联操作  BaseLanguageDto 重写方法 
	 * null ,searchValue ,searchValueInfo, searchValue、 searchValueInfo
	 */
	@Override
	public Pagination<BaseLanguageDto> pageLaguageList(Pagination<BaseLanguageDto> pager, String searchValue,
			String searchValueInfo) {
		// TODO Auto-generated method stub
		StringBuffer sql= null;
		sql= new StringBuffer(" select l.base_language_id,l.l_key,l.en_val,l.cn_val,l.ext_val_one,l.ext_val_two,i.module_name ")
					.append(" from base_language l ")
					.append(" left join module_info i  ")
					.append(" on l.module_info_id = i.module_info_id ")
					.append(" where i.module_is_delete= 0  ");
		List<Object> params= new ArrayList<Object>();
		//模块编号不为空，lkey为空
		if( StringUtils.isNotBlank(searchValueInfo) && StringUtils.isBlank(searchValue)){
				 sql.append(" and i.module_name ='"+searchValueInfo+"' "); 
		}
		//模块编号为空，lkey不为空
		if(StringUtils.isNotBlank(searchValue)&& StringUtils.isBlank(searchValueInfo)){
			sql.append(" and l.l_key like ? ");
					params.add("%"+searchValue+"%");
		}
		//判断moduleInfo_id、lkey都不为空
		if(StringUtils.isNotBlank(searchValue) && StringUtils.isNotBlank(searchValueInfo)){
			sql.append(" and i.module_name ='"+searchValueInfo+"' "); 
			sql.append(" and l.l_key like ? ");
		    params.add("%"+searchValue+"%");
		 }
		
		if(StringUtils.isNotBlank(pager.getOrderBy()) && StringUtils.isNotBlank(pager.getSort())){
			sql.append(" order by r."+pager.getOrderBy().toUpperCase() +" "+pager.getSort().toUpperCase());
		 }else{
			 sql.append(" order by base_language_id asc ");
		 }
		 
		return this.queryListByPage(pager, sql.toString(),params,BaseLanguageDto.class);
	}

}
